//
//  PatternMatchingViewController.swift
//  test_swift
//
//  Created by fangyuan ding on 2021/6/1.
//

import UIKit

class PatternMatchingViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
//        let point = (3, 2)
//        switch point {
//        //将point 中的元素绑定到 x 和 y
//           case let (x, y):
//            print("The point is at (\(x), \(y))")
//        }
//        let points = [(3, 0), (1, 0), (0, 0), (9, 1)]
//        for (x, y) in points where y == 0 {
//            print("\(x) and \(y)")
//        }
//
//        let someOptional: Int? = 42
//        //使用枚举事例模式匹配
//        if case .some(let x) = someOptional {
//            print(x)
//        }
//        //使用可选模式匹配
//        if case let x? = someOptional {
//            print(x)
//        }
//
//        let arrayOfOptionalInts: [Int?] = [nil, 2, 3, nil, 5]
//        //仅匹配非 nil 值。
//        for case let number? in arrayOfOptionalInts {
//            print("Found a \(number)")
//        }
        
        
        
        let point = (1, 2)
        switch point {
        case (0, 0):
            print("(0, 0) is at the origin.")
        case (-2...2, -2...2):
            print("(\(point.0), \(point.1)) is near the origin")
        default:
            print("The point is at (\(point.0), \(point.1))")
        }
        
        
    }
    



}
